import type { IDS, PageQuery, PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

export interface OperationLog {
  id: string;
  tenantId: string;
  title: string;
  businessType: number;
  businessTypes?: any;
  method: string;
  requestMethod: string;
  operatorType: number;
  operName: string;
  deptName: string;
  operUrl: string;
  operIp: string;
  operLocation: string;
  operParam: string;
  jsonResult: string;
  status: number;
  errorMsg: string;
  operTime: string;
  costTime: number;
}

enum Api {
  operLogClean = '/common/monitor/operlog/clean',
  operLogExport = '/common/monitor/operlog/export',
  operLogList = '/common/monitor/operlog/page',
  root = '/common/monitor/operlog',
}

/**
 * 操作日志分页
 * @param params 查询参数
 * @returns 分页结果
 */
export function operLogList(params?: PageQuery) {
  return requestClient.get<PageResult<OperationLog>>(Api.operLogList, {
    params,
  });
}

/**
 * 删除操作日志
 * @param operIds id/ids
 */
export function operLogDelete(operIds: IDS) {
  return requestClient.delete(`${Api.root}/${operIds}`);
}

/**
 * 清空全部分页日志
 */
export function cleanAll() {
  return requestClient.delete(Api.operLogClean);
}

/**
 * 导出操作日志
 * @param data 查询参数
 */
export function operLogExport(data: Partial<OperationLog>) {
  return commonExport(Api.operLogExport, data);
  // return requestClient.download(Api.operLogExport, { data });
}
